#include"MyList.hpp"
namespace MyList{
 

  void MyList_test1()
  {

    list<int>ls;
    ls.push_back(2);
    ls.push_back(2);
    ls.push_back(2);
    ls.push_back(2);
    ls.push_back(2);
    ls.push_back(2);
    
    //测试迭代器与范围for
    list<int>::iterator it = ls.begin();
    /*
     * 这里将调用拷贝构造函数
     * 但并不需要调用深拷贝，由于iterator中所存在的对象只有指针
     * 调用默认生成的拷贝构造函数时将进行值拷贝
     * 但是这里只需要的就是值拷贝 所以不需要显示定义拷贝构造函数
     */                              
   
    while(it != ls.end()){
        cout<<*it<<" ";
        ++it;
    }
    cout<<endl;
    
    for(const auto& e:ls){
      //同时这里使用范围for的话需要用引用\
      //因为不能保证该模板参数是内置类型还是自定义类型
      cout<<e<<" ";
    }
    cout<<endl;
  }

  //---------------------------------
  
  struct AA{
    int _a1;
    int _a2;
    AA(int a1 = 0,int a2 = 0)
      :_a1(a1)
       ,_a2(a2)
    {}
    //没有重载流插入 所以打印时会报错
  };

  void MyList_test2(){
   list<AA> ls;//自定义类型在作为参数时会去调用它的默认构造 
    // 这里包括模板类型
   ls.push_back(AA(1,1));
   ls.push_back(AA(2,2));
   ls.push_back(AA(3,3));
   ls.push_back(AA(4,4));
   
   list<AA>::iterator it = ls.begin();
   while(it!=ls.end()){
    // cout<<*it<<" ";  //erro - 未对流插入进行重载 所以不可直接打印
    //cout<<(*it)._a1<<":"<<(*it)._a2<<endl;//未重载->时的繁琐用法
    cout<<it->_a1<<":"<<it->_a2<<endl;//重载->后的用法

    cout<<it.operator->()/* 返回AA* */->_a1/*再通过该指针解引用*/<<" "<<
        it.operator->()->_a2<<endl;//原始状态
    ++it;

   }
  }
  void MyList_test3(){
   list<int> ls;//自定义类型在作为参数时会去调用它的默认构造 
   ls.push_back(1);
   ls.push_back(1);
   ls.push_back(1);
   ls.push_back(1);
   ls.push_back(1);
   ls.push_back(1);
   
   list<int>::iterator it = ls.begin();
   while(it!=ls.end()){
    cout<<*it<<" ";
     ++it;
   }
    cout<<endl;

    it = ls.begin();
   ls.insert(it,6);
   it = ls.begin();
   while(it!=ls.end()){
    cout<<*it<<" ";
     ++it;
   }
    cout<<endl;

    ls.push_back(66);
    ls.push_front(66);
   it = ls.begin();
   while(it!=ls.end()){
    cout<<*it<<" ";
     ++it;
   }
    cout<<endl;

    ls.pop_back();
    ls.pop_front();
   it = ls.begin();
   while(it!=ls.end()){
    cout<<*it<<" ";
     ++it;
   }
    cout<<endl;
  }


  void MyList_test4(){
    list<int> lt;
    lt.push_back(1);
    lt.push_back(1);
    lt.push_back(1);
    lt.push_back(1);
    lt.push_back(1);
    
    for(auto &it:lt){
      cout<<it<<" ";
    }
    cout<<endl;

    lt.clear();

    for(auto &it:lt){
      cout<<it<<" ";
    }
    cout<<endl;

    lt.push_back(10);
    lt.push_back(1);
    lt.push_back(1);
    lt.push_back(1);
    lt.push_back(110);
    
    for(auto &it:lt){
      cout<<it<<" ";
    }
    cout<<endl;

    /*int a = 10;
    const int*pa = &a;
    cout<<*pa<<endl;
   // *pa = 20; - erro
    pa++;*/

    list<int> lt2(lt);

    for(auto &it:lt2){
      cout<<it<<" ";
    }
    cout<<endl;
  }

  void MyList_test5(){
    //测试赋值重载
    list<int> lt;
    lt.push_back(1);
    lt.push_back(1);
    lt.push_back(1);
    lt.push_back(1);
    lt.push_back(1);
    
    for(auto &it:lt){
      cout<<it<<" ";
    }
    cout<<endl;

    list<int> lt2;
    lt2.push_back(2);
    lt2.push_back(3);
    lt2.push_back(4);
    lt2.push_back(5);
    lt2.push_back(6);

    lt = lt2;

    for(auto &it:lt){
      cout<<it<<" ";
    }
    cout<<endl;


    for(auto &it:lt2){
      cout<<it<<" ";
    }
    cout<<endl;
  }
}

#include<vector>
#include<string>
#include<typeinfo>
  void _test4(){
    std::vector<int>::iterator it;
    std::string::iterator sit;
    cout<<typeid(it).name()<<endl;
    cout<<typeid(sit).name()<<endl;
    //未知问题
  }
  
int main()
  {
    // MyList::MyList_test1();
    // MyList::MyList_test2();
    // MyList::MyList_test3();
   // MyList::MyList_test4();//测试clear
    // _test4();//测试vector底层是否为原生指针

    MyList::MyList_test5();//测试赋值重载
    
    return 0;
  }
